<template>
    <div class="order-report">
        <div class="report-table-top-title">报钟器管理</div>
        <div class="report-table-form1">
            <div class="report-table-form1-line">
                <div
                    class="report-table-form1-item word samll"
                    style="width: 50px"
                >
                    代理商:
                </div>
                <div class="report-table-form1-item" style="width: 180px">
                    <el-select
                        class="items"
                        v-model="searchParam.agentId"
                        filterable
                        remote
                        clearable
                        reserve-keyword
                        :remote-method="remoteMethod"
                        :loading="loading"
                        placeholder="请输入代理商"
                        size="small"
                    >
                        <el-option
                            v-for="item in agentList"
                            :key="item.id"
                            :label="item.agentName"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 50px"
                >
                    SN码:
                </div>
                <div class="report-table-form1-item" style="width: 180px">
                    <el-input
                        class="items"
                        v-model="searchParam.chipCode"
                        placeholder
                        size="small"
                        suffix-icon="el-icon-search"
                    ></el-input>
                </div>
                <el-button type="primary" size="small" @click="reSearch"
                    >搜索</el-button
                >
                <el-button
                    type="primary"
                    size="small"
                    @click="$emit('detail', {})"
                    >新增</el-button
                >
            </div>
        </div>
        <div class="page-padding-gray-small"></div>
        <div class="report-table-wrapper">
            <el-table
                :header-cell-style="headerCellStyle"
                size="small"
                :data="tabData"
                border
                style="width: 100%"
            >
                <el-table-column
                    prop="agentName"
                    label="代理商名称"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="chipCode"
                    label="SN码"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="inputTime"
                    label="录入时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="deliveryTime"
                    label="发货时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column label="操作" width="150px">
                    <template slot-scope="scope">
                        <el-button
                            plain
                            type="primary"
                            @click="$emit('detail', scope.row)"
                            size="small"
                            >编辑</el-button
                        >
                        <el-button
                            plain
                            type="danger"
                            @click="delRow(scope.row)"
                            size="small"
                            >删除</el-button
                        >
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 分页 -->
        <div class="report-table-block" v-show="totalNum > pageSize">
            <div class="report-table-block-in">
                <el-pagination
                    background
                    :current-page.sync="currentPage"
                    @current-change="handleCurrentChange"
                    :page-size="pageSize"
                    layout="prev, pager, next, total"
                    :total="totalNum"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
export default {
    data: function () {
        return {
            row: null,
            loading: false,
            isShow: false,
            searchParam: {
                agentId: '',
                chipCode: ''
            },
            // rules: {
            //     agentId: [
            //         { required: true, message: '请输入', trigger: 'blur' }
            //     ],
            //     chipCode: [
            //         { required: true, message: '请输入', trigger: 'blur' }
            //     ]
            // },
            agentList: [],
            currentPage: 1,
            pageSize: 10,
            totalNum: 0,
            tabData: [],
            size: 100
        }
    },
    mounted () {
    },
    created () {
        // this.getAllAgent()
        this.getList()
    },
    watch: {
    },
    props: {
        underLine: null
    },
    computed: {
        ip () {
            return this.$store.state.IP
        }
    },
    methods: {
        delRow (row) {
            console.log(row)
            this.$confirm('确定删除吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let params = {
                    params: {
                    }
                }
                this.$http.get(this.$store.state.IP + '/stoneOrderManage/deleteStoneOrder?id=' + row.id, params).then(response => {
                    response = response.body
                    console.log(response)
                    if (response.ret === '0') {
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        })
                        this.getList()
                    }
                }, response => {
                    console.log('调用添加失败')
                })
            }).catch(() => {
            })
        },
        remoteMethod (query) {
            if (query !== '') {
                this.loading = true
                this.getAnageList(query)
            } else {
                this.agentList = []
            }
        },
        getAnageList (agentName) {
            // 获取 所有 代理商列表
            let params = {
                params: {
                }
            }
            this.$http.get(this.$store.state.IP + '/stoneOrderManage/selectAgent?agentName=' + agentName, params).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    console.log('调用获取所有代理商成功')
                    this.agentList = response.res
                    this.loading = false
                }
                if (response.ret !== '0') {
                    this.loading = false
                    console.log('调用获取所有代理商失败')
                }
                console.log('******************************************')
            }, response => {
                this.loading = false
                console.log('通讯失败')
            })
        },
        begintimeChange (value) {
            // 开始时间 选择
            this.searchParam.begintime = value
            // this.checkDate()
        },
        endtimeChange (value) {
            // 选择结束时间
            this.searchParam.endtime = value
            // this.checkDate()
        },
        checkDate () {
            // 对比 日期，小的 放前面
            let date1 = new Date(this.searchParam.begintime).getTime()
            let date2 = new Date(this.searchParam.endtime).getTime()
            if (date1 > date2) {
                let temp = this.searchParam.begintime
                this.searchParam.begintime = this.searchParam.endtime
                this.searchParam.endtime = temp
            }
        },
        handleCurrentChange (page) {
            // 换页
            this.currentPage = page
            this.getList()
        },
        reSearch () {
            this.currentPage = 1
            this.getList()
        },
        getList () {
            // 获取 所有 服务列表
            this.$http.post(this.$store.state.IP + '/stoneOrderManage/stoneOrderList', {
                agentId: this.searchParam.agentId,
                chipCode: this.searchParam.chipCode,
                page: this.currentPage - 1,
                size: this.pageSize
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                response = response.body
                this.tabData = []
                if (response.ret === '0') {
                    this.tabData = response.res.list
                    this.totalNum = response.res.total
                }
                if (response.ret !== '0') {
                    console.log('调用获取所有代理商失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
.order-report
    width: 100%
    background: #fff
    min-height: calc(100vh - 65px)
    position: relative

    .report-table-top-title
        width: 100%
        height: 64px
        line-height: 64px
        color: #000
        font-size: 18px
        background: #f1f0f5

    .report-table-form1
        width: 100%
        min-height: 40px
        padding: 16px 0 0 22px
        box-sizing: border-box
        background: #fff
        overflow: hidden

        .report-table-form1-line
            min-height: 32px
            margin-bottom: 16px

            .report-table-form1-item
                display: inline-block
                vertical-align: top
                height: 32px
                margin-right: 15px
                line-height: 32px

                &.word
                    margin-right: 0

                &.samll
                    font-size: 15px
                    text-align: left

                &.big
                    margin-right: 100px

    .report-table-block
        width: 100%
        padding-top: 22px
        height: 50px
        background: #fff
        box-sizing: border-box

        .report-table-block-in
            float: right
            padding-right: 17px

    .page-padding-gray-small
        width: 100%
        height: 22px
        background: #f1f0f5

    .page-padding
        width: 100%
        height: 20px
        background: #fff

    .report-table-total
        width: 100%
        font-size: 16px
        color: #409EFF
        padding: 22px
        margin-top: 22px
        box-sizing: border-box
        background: #fff

    .page-all-loading
        position: fixed
        top: 55%
        left: 40%
        width: 200px

.title
    display: inline-block
    min-width: 120px
    text-align: right
    font-weight: bold
    line-height: 35px

.value
    display: inline-block
    line-height: 35px
    min-width: 150px

.items
    width: 180px

.item
    margin-bottom: 0px
</style>

